﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ContinuumSL
{
    public partial class PasswordChildWindow : ChildWindow
    {
        public string Password { get; set; }
        public string OperationMode = "";

        public event EventHandler SubmitClicked;

        public PasswordChildWindow()
        {
            InitializeComponent();
        }

        public void SetupSetPassword()
        {
            OperationMode = "Set";

            this.Title = "Set Continuum Password";

            passwordBox.Password = "";
            passwordBoxConfirm.Password = "";

            passwordBoxConfirm.Visibility = System.Windows.Visibility.Visible;
            lblConfirm.Visibility = System.Windows.Visibility.Visible;
        }

        public void SetupEnterPassword()
        {
            OperationMode = "Enter";

            this.Title = "Enter Continuum Password";
            lblPassword.Text = "Password :";
            passwordBox.Password = "";

            this.Height = 180;
            passwordBoxConfirm.Visibility = System.Windows.Visibility.Collapsed;
            lblConfirm.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            OkClicked();
        }

        private void passwordBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter) OkClicked();
        }

        private void OkClicked()
        {
            if (OperationMode == "Set")
            {
                if (passwordBox.Password != passwordBoxConfirm.Password)
                {
                    MessageBox.Show("Passwords to not match", "Unable to set password", MessageBoxButton.OK);
                    return;
                }
            }

            Password = passwordBox.Password;
            SubmitClicked(this, new EventArgs());
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void passwordBoxConfirm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter) OkClicked();
        }

    }
}

